/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.hugegraph.store.client;

import static org.apache.hugegraph.store.client.util.HgAssert.isFalse;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import javax.annotation.concurrent.NotThreadSafe;

/**
 * created on 2021/10/26
 *
 * @version 1.0.0
 */
@NotThreadSafe
public final class HgNodePartitionerBuilder {

    private Set<HgNodePartition> partitions = null;

    static HgNodePartitionerBuilder resetAndGet() {
        return new HgNodePartitionerBuilder();
    }

    /**
     * @param nodeId
     * @param keyCode
     * @return
     * @see HgNodePartitionerBuilder:setPartitions(Set<HgNodePartition> partitions)
     */
    @Deprecated
    public HgNodePartitionerBuilder add(Long nodeId, Integer keyCode) {
        isFalse(nodeId == null, "The argument is invalid: nodeId");
        isFalse(keyCode == null, "The argument is invalid: keyCode");

        if (this.partitions == null) {
            this.partitions = new HashSet<>(16, 1);
        }

        this.partitions.add(HgNodePartition.of(nodeId, keyCode));
        return this;
    }

    Collection<HgNodePartition> getPartitions() {
        return this.partitions;
    }

    public void setPartitions(Set<HgNodePartition> partitions) {
        isFalse(partitions == null, "The argument is invalid: partitions");
        this.partitions = partitions;
    }

}
